package com.hopital5.zhangyz.model;

import lombok.*;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.OneToMany;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Entity
@Data
@EqualsAndHashCode(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Activity extends BaseModelAndLongId {
    private Date beginDate;
    private Date endDate;
    private String name;
    @OneToMany(mappedBy = "activity", cascade = {CascadeType.MERGE, CascadeType.PERSIST})
    private List<ActivityActivityItem> activityActivityItems;

    public Activity addActivityActivityItem(ActivityActivityItem activityActivityItem) {
        if (this.activityActivityItems == null) {
            this.activityActivityItems = new ArrayList<>();
        }
        this.activityActivityItems.add(activityActivityItem);
        activityActivityItem.setActivity(this);
        return this;
    }
}
